package solution._0020._0024;

import common.ListNode;

/**
 * Created by chen_snow
 * Date: 2021/5/14 22:55
 * Description: 两两交换链表中的节点
 */
public class Solution {
    public ListNode swapPairs(ListNode head) {
        return swap(head);
    }

    public ListNode swap(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }

        ListNode first = head;
        ListNode second = head.next;

        first.next = swap(second.next);
        second.next = first;

        return second;
    }
}
